﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Parichay.Data.Helper;

namespace Parichay.Data.Repository
{
    public class MemberPostsRepository : Parichay.Domain.Interface.Data.IMemberPostsRepository
    {
        private Parichay.Domain.Interface.Data.IMemberRepository _memberRepository;

        public MemberPostsRepository(Parichay.Domain.Interface.Data.IMemberRepository memberRepository)
        {
            this._memberRepository = memberRepository;
        }

        public Domain.MemberPosts GetMemberPostById(int id)
        {
            throw new NotImplementedException();
        }

        public bool AddMemberPost(Domain.MemberPosts model)
        {
            throw new NotImplementedException();
        }

        public void DeleteMemberPost(int id)
        {
            throw new NotImplementedException();
        }

        public bool ReplyMemberPost(int id, int rId, Domain.MemberPosts model)
        {
            throw new NotImplementedException();
        }

        public IList<Domain.MemberPosts> GetMemberPostsByUserId(int userId, int pageSize, int pageIndex)
        {
            IList<Parichay.Domain.MemberPosts> lst = Data.Helper.NHibernateHelper.ConvertToListOf<Parichay.Domain.MemberPosts>(Data.Helper.NHibernateHelper.Find("select distinct p from MemberPosts as p where p.Sender.Id=? and p.Recipient.Id=? order by p.Createdon desc", new object[] { userId, userId }, new NHibernate.Type.IType[] { NHibernate.NHibernateUtil.Int32, NHibernate.NHibernateUtil.Int32 }, false));
            return (lst);
        }

        public IList<Domain.MemberPosts> GetFriendsMemberPostsByUserId(int userId, int pageSize, int pageIndex)
        {
            IList<Domain.MemberPosts> lst = null;

            int[] intIds = _memberRepository.getFriendIds(userId);

            if (intIds != null && intIds.Length != 0)
            {
                object[] friendIds = new object[intIds.Length];

                for (int temp = 0; temp < intIds.Length; temp++)
                {
                    friendIds[temp] = intIds[temp];
                }


                lst = Data.Helper.NHibernateHelper.ConvertToListOf<Domain.MemberPosts>(Data.Helper.NHibernateHelper.FindByListParameter("from MemberPosts as m  where ((m.Sender.Id = m.Recipient.Id) and m.Sender.Id in (:friendIds)) order by m.Createdon desc", "friendIds", friendIds, NHibernate.NHibernateUtil.Int32, false));

            }
            //msgs.SortDescending(m => m.Createdon);
            return (lst);
        }

        public IList<Domain.MemberPosts> GetMemberPostsByDate(int userId, DateTime startDate, DateTime endDate)
        {
            throw new NotImplementedException();
        }
    }
}
